import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import Item from '../Item'
import './index.css'
export default class Showbox extends Component {
  state={requestList:[],isLoding:false,err:''}
  componentDidMount(){
    //接收数据的一方订阅事件名称
    this.token=PubSub.subscribe('changeAppState',(msg,obj)=>{
      this.setState(obj)
    })
  }
  componentWillUnmount(){
    //组件卸载时取消订阅
    PubSub.unsubscribe(this.token)
  }
  render() {
    const {requestList,isLoading,err}=this.state
    return (
      <div className='showbox'>
        {
          isLoading?<h1>Loading.......</h1>:
          err?<h1>{err}</h1>:
          requestList.map((val,index)=>{
            return (
              <Item userMsg={val} key={val.node_id}></Item>
            )
          })
        }
        
      </div>
    )
  }
}
